# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=lotide
pkgver=0.15.0
pkgrel=0
_hitide="${pkgver%.*}.0"
pkgdesc="Federated forum / link aggregator using ActivityPub"
url="https://sr.ht/~vpzom/lotide/"
# loongarch64: blocked by libc crate
arch="all !loongarch64"
license="AGPL-3.0-or-later"
makedepends="cargo cargo-auditable openssl-dev zlib-dev"
install="lotide.pre-install lotide.post-install hitide.pre-install"
pkgusers="lotide"
pkggroups="lotide"
subpackages="lotide-openrc hitide hitide-openrc:_hitide_openrc:noarch"
source="lotide-$pkgver.tar.gz::https://git.sr.ht/~vpzom/lotide/archive/v$pkgver.tar.gz
	hitide-$_hitide.tar.gz::https://git.sr.ht/~vpzom/hitide/archive/v$_hitide.tar.gz
	cargo-update-libc_patch

	lotide.initd lotide.confd
	hitide.initd hitide.confd
	"
builddir="$srcdir/$pkgname-v$pkgver"
options="!check" # Requires running database

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked

	cd "../hitide-v$_hitide"
	patch Cargo.lock "$srcdir"/cargo-update-libc_patch

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release

	cd "../hitide-v$_hitide"

	cargo auditable build --frozen --release
}

check() {
	cargo test --frozen

	cd "../hitide-v$_hitide"

	cargo test --frozen
}

package() {
	install -Dvm755 target/release/lotide -t "$pkgdir"/usr/bin/

	install -dm750 -o lotide -g lotide "$pkgdir"/var/lib/lotide
	install -dm750 -o lotide -g lotide "$pkgdir"/var/lib/lotide/media

	install -Dm755 "$srcdir"/lotide.initd "$pkgdir"/etc/init.d/lotide
	install -Dm644 "$srcdir"/lotide.confd "$pkgdir"/etc/conf.d/lotide

	cd "../hitide-v$_hitide"

	install -Dvm755 target/release/hitide -t "$pkgdir"/usr/bin/
}

hitide() {
	pkgdesc="$pkgdesc (web UI frontend)"

	amove usr/bin/hitide
}

_hitide_openrc() {
	pkgdesc="$pkgdesc (OpenRC init scripts for web UI frontend)"
	install_if="openrc hitide=$pkgver-r$pkgrel"

	install -Dm755 "$srcdir"/hitide.initd "$subpkgdir"/etc/init.d/hitide
	install -Dm644 "$srcdir"/hitide.confd "$subpkgdir"/etc/conf.d/hitide
}

sha512sums="
f6c49e58207644eea17a847a4a38f23765322e030fdfe79f6aec27312217a42f10c830047f87de1441d45856a3f53dc02247b934fe9b85cbe36ca83d251b7497  lotide-0.15.0.tar.gz
3888c09e51005faf55bd2a7d9772398f318ed01b016bf1af265b94ad6d3e3272b8d5fe163629f2227e8ec9638da196393c040dcacf4100ab1616a741de2545b2  hitide-0.15.0.tar.gz
753b55edaa323cd7d777a994ebfc365036e1031f81f31e4907181dd2acf94e3f77e3ce0b49c1ccb73f801687f385d263506276c48fe627f56b906421251b9ed7  cargo-update-libc_patch
ba052e36c230192c4b5eb3d3f47c39c00ecc4bfb8722bada4101b7367f9c49713ae3de5688680c556b4c3042ce338b8bd0e20b85d5367e1f541b38669bba64cd  lotide.initd
a8c10e2d17118bdc7701330a3f2e6930c8e3a85162174792f7ee314b4bb8ee4d21954a32689282ab5ed75edda588fbc84ab6c309c346b8dde5910fcf7a4dcaec  lotide.confd
83a27192d78fc399cf4b3158fe687efb6155c183812444657a42938f91ef5d8c675f46af365ecb677bf728158868a2fd9a80a3e1ca479ab810f4a7909d711168  hitide.initd
f715ea4d941d45bdd7773d0450049333ab48d9d7292c7aa17bcf26109246f33289ddeae92e4a06457a4209a0a65248d67a13736e3be7126378c890776aa515d6  hitide.confd
"
